<template>
	<view class="box" :style="theme">
		<u-sticky bgColor="#fff" style="top: 0;">
			<u-tabs :list="tab" lineHeight="6rpx" :scrollable="false"
				:activeStyle="{fontWeight: 'bolder',fontSize: '28rpx',color: '#222222'}"
				:inactiveStyle="{fontSize: '28rpx'}" @click="tabclick" :current="swiperIndex"></u-tabs>
			<scroll-view scroll-x v-if="table&&table.length>0" class="box_tabls">
				<view class="box_tabls_left">
					<view class="box_tabls_left_item" :class="activeIndex == index ? 'active' : ''"
						v-for="(item, index) in table" :key="index" @click="clickTbas(index)">{{item.projectName}}
					</view>
				</view>
				<!-- <view v-if="isOpen" class="box_tabls_right">
					<u-icon :name="isOpen?'arrow-down':'arrow-up'" @click="clickIcon" />
				</view> -->
			</scroll-view>
		</u-sticky>
		<view class="box_piao">
			<view class="box_piao_item" v-for="(item, index) in list" :key="index"
				@click="jump2('/pages/home/receiveCoupons?id=',item.couponsId)">
				<view class="box_piao_item_left" :class="item.remaining > 0?'':'hui'">
					<view class="feilei">{{item.couponsType == 0 ? '折扣券' : '代金券'}}</view>
					<view class="type" v-if="item.couponsType == '1'">{{item.discountNum}}<text>元</text></view>
					<view class="type" v-if="item.couponsType == '0'">{{ item.discountNum }}<text>折</text></view>
					<!-- 	<text v-if="item.validityType == 1">{{item.validityDays}}天内有效</text> -->
					<!-- 	<text v-if="item.validityType == 0">截至{{item.validityEndTime}}</text> -->
					<view class="box_piao_item_left_a"></view>
					<view class="box_piao_item_left_b"></view>
				</view>
				<view class="box_piao_item_right">
					<view class="bt">{{item.couponsName}}</view>
					<view v-if="item.couponsType == 0" class="js limit-2-line">订单满{{item.miniNum}}享{{item.discountNum}}折</view>
					<view v-else class="js limit-2-line">订单满{{item.miniNum}}减{{item.discountNum}}元</view>
					<view class="box_piao_item_right_lq">
						<text v-if="item.remaining > 0">去领取</text>
						<image v-if="item.remaining > 0" :src="imgHost+'/ticket_ic_more.png'"></image>
						<text v-else class="hui">已领完</text>
					</view>
				</view>
			</view>
		</view>
		<view v-if="list.length === 0" class="no-order">
			<image :src="imgHost+'/default_nodata.png'"></image>
			<view>暂无数据</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				table: [],
				list: [],
				activeIndex: 0,
				noClick: true,
				isOpen: true,
				tab: [{
					name: "全部",
					triggered: false,
				}, {
					name: "代金券",
					triggered: false,
				}, {
					name: "折扣券",
					triggered: false,
				}],
				swiperIndex: 0
			}
		},
		onLoad() {
			this.getProject()
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			tabclick(e) {
				this.swiperIndex = e.index;
				this.list = []
				this.getList()
			},
			// 点击箭头
			clickIcon() {
				this.isOpen = !this.isOpen
			},
			clickTbas(index) {
				this.activeIndex = index
				this.list = [];
				this.getList()
			},
			getProject() {
				this.$app.ajax({
					data: {
						param: {
							venueId: this.venueId,
							projectName: '',
							status: '1',
						}
					},
					api: this.$api.getProject()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.table = [{
							projectName: '全部',
							id: ''
						}, ...res.recordList]
						this.getList()
					}
				}).catch(() => {})
			},
			getList() {
				let couponsType
				if (this.swiperIndex == 1) {
					couponsType = '1'
				} else if (this.swiperIndex == 2) {
					couponsType = '0'
				}
				this.$app.ajax({
					api: this.$api.collectCoupons(),
					data: {
						param: {
							couponsType,
							isMult: '1',
							itemsId: this.table[this.activeIndex].id,
							stadiumId: this.venueId
						}
					}
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.list = res.recordList || []
					}
				}).catch(() => {})
			}

		}

	}
</script>
<style lang="scss" scoped>
	.box_tabls {
		display: flex;
		justify-content: space-between;
		padding: 30rpx;
		background: #ffffff;
		position: sticky;
		top: 0;
		left: 0;
		right: 0;
		overflow: hidden;
	
		.box_tabls_left {
			white-space: nowrap;
			display: flex;
	
			.box_tabls_left_item {
				padding: 0 46rpx;
				line-height: 70rpx;
				border-radius: 35rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: #111111;
				background: $bjColor;
				margin-right: 16rpx;
	
				&:last-of-type {
					margin-right: 0;
				}
	
				&.active {
					color: #ffffff;
					background: $color;
				}
			}
		}
	}

	.box_piao {
		padding: 24rpx 30rpx;
		box-sizing: border-box;
	}

	.box_piao_item {
		height: 180rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #ffffff;
		border-radius: 15rpx;
		overflow: hidden;
		margin-bottom: 24rpx;
	}

	.box_piao_item_left {
		width: 180rpx;
		height: 180rpx;
		display: flex;
		flex-shrink: 0;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		position: relative;
		background: $color;
		box-shadow: inset 0px 2rpx 4rpx 0px rgba(255, 255, 255, 0.47);
		color: #fff;
		&.hui {
			color: #888888;
			background: #DDDDDD;
		}
		.box_piao_item_left_a {
			position: absolute;
			right: -15rpx;
			top: -15rpx;
			width: 30rpx;
			height: 30rpx;
			border-radius: 50%;
			background: #F7F7F7;
		}
		
		.box_piao_item_left_b {
			position: absolute;
			right: -15rpx;
			bottom: -15rpx;
			width: 30rpx;
			height: 30rpx;
			border-radius: 50%;
			background: #F7F7F7;
		}
		.feilei {
			font-size: 24rpx;
			font-weight: 400;
		}
		.type {
			font-size: 44rpx;
			font-weight: 500;
			margin: 5rpx 0;
			text {
				font-size: 24rpx;
				font-weight: 500;
			}
		}
	}
	.box_piao_item_right {
		flex: 1;
		height: 100%;
		display: flex;
		flex-direction: column;
		position: relative;
		padding: 30rpx;
		box-sizing: border-box;

		.bt {
			font-size: 30rpx;
			font-weight: 500;
			color: #222222;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		.js {
			font-size: 24rpx;
			color: #333333;
			margin-top: 10rpx;
		}

		.box_piao_item_right_lq {
			display: flex;
			align-items: center;
			justify-content: space-between;
			position: absolute;
			right: 30rpx;
			bottom: 30rpx;

			text {
				font-size: 26rpx;
				color: $color;
				&.hui {
					color: #888888;
				}
			}

			image {
				width: 30rpx;
				height: 30rpx;
				margin-left: 8rpx;
				flex-shrink: 0;
			}
		}
	}
</style>